/*****************************************************************************************
This file is a part of Arise library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

Arise Engine		Logfile.cpp

					E-mail:	arise_engine@mail.ru

					Origin by irek;					
					Modified for DK Engine 0.019:
					dev (avon.dn.ua@gmail.com), Agressor (agress0r@mail.ru)

created:			12.08.2003
last changes:		06.02.2008
************************************************************************/
#include "stdafx.h"


//	case 0: color = "blue"
//	case 1:	color = "red"
//	case 2:	color = "orange"
//	case 3:	color = "yellow"
//	case 4:	color = "green"
//	case 5:	color = "gray"
//	case 6:	color = "darkviolet"

Logfile::Logfile()
{
}
Logfile::Logfile(const std::string file_name, float version)
{
	m_log_file.open(file_name.c_str(), std::ios::out);

	_strtime(Timer);

	char date[TIME_NUM_SYMBOLS];
	_strdate(date);

	m_log_file	<<"<Title>Arise Engine Log File</Title>"
				<<"<Html><Body BgColor = "LOG_BG_COLOR_DEFAULT">"
				<<"<B><Font Size = 5 color = "LOG_FONT_COLOR_DEFAULT" Face = "LOG_FONT_DEFAULT">Arise Engine Log File</B><BR>"
				<<"<Font Size = 2 color = "LOG_FONT_COLOR_DEFAULT" Face = "LOG_FONT_DEFAULT">Build version:"<<version<<"<br>"
				<<"Log created "<<date<<" "<<Timer<<"<BR><BR><BR>"
				<<"-----------------------------------------------------------------------------------"
				<<std::endl;
}
Logfile::~Logfile()
{
	m_log_file <<"</Font></P></Body></Html>"<<std::endl;
	m_log_file.close();
}


void Logfile::AddTimerData()
{
	GetLocalTime(&m_system_time);
	_strtime(Timer);

	m_log_file	<<Timer
				<<"::"
				<<m_system_time.wMilliseconds	
				<<" "
				<<std::endl;
}


void Logfile::log(const UINT type, const char* string, const char* title)
{
	if (!string) return;
	
	char* color = 0;
	switch(type)
	{
		case 0: case 10: case 20:	color = LOG_FONT_COLOR_DEFAULT; break;
		case 1:	case 11: case 21:	color = "red";					break;
		case 2:	case 12: case 22:	color = "orange";				break;
		case 3:	case 13: case 23:	color = "yellow";				break;
		case 4:	case 14: case 24:	color = "green";				break;
		case 5:	case 15: case 25:	color = "gray";					break;
		case 6:	case 16: case 26:	color = "darkviolet";			break;
		case 7:	case 17: case 27:	color = "brown";				break;
		
		case 99:					color = "red";					break;

		default:					color = LOG_FONT_COLOR_DEFAULT;	break; 
	}

	m_log_file	<<"<BR><Font Size= "<<LOG_FONT_SIZE_DEFAULT 
					<<" Color="<<color
					<<" Face=" <<LOG_FONT_DEFAULT<<">"
					<<std::endl;

	AddTimerData();
	
	switch(type)
	{
		case 0:
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
			m_log_file <<string<<std::endl; 
			break; 
		
		case 10:
		case 11:
		case 12:
		case 13:
		case 14:
		case 15:
		case 16:
		case 17:
			m_log_file<<"<i>"<<string<<"</i>"<<std::endl; 
			break;

		case 20:
		case 21:
		case 22:
		case 23:
		case 24:
		case 25:
		case 26:
		case 27:
			m_log_file<<"<b>"<<string<<"</b>"<<std::endl; 
			break;

		case 99:					
			m_log_file<<"<i><b>"<<string<<"</b></i>"<<std::endl; 
			if(title)	MessageBox(NULL, string, title, MB_ICONERROR);
			else		MessageBox(NULL, string, MESSAGE_BOX_TITLE, MB_ICONERROR);
			
			break;

		default:
			m_log_file <<string<<std::endl; break; 
	}


}








